#!/usr/bin/env bash
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# Function :CentOS7.X 安装 gogs
# Platform :RedHatEL7.x Based Platform
# Version  :1.2
# Date     :2021-07-06
# Author   :mugoLH
# Contact  :houxiaoshuai@baidu.com & hxsaj@126.com
# Company  :
# depend on:
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
#  变量列表 Variable list
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
DB_VOLUME=/app/db
DB_PORT=2306
MYSQL_ROOT_PASSWORD=594hxs
APP_VOLUME=/app
GOGS_PORT=8001
GOGS_SSH=8002

#  安装 dokcer 版本 mariadb
function docker_mariadb(){
	#  拉取 mariadb
	docker pull mariadb
	#  创建数据库数据卷
	if [ ! -d ${DB_VOLUME} ];then
		mkdir -p ${DB_VOLUME}
	fi
	#  启动 mariadb 数据库
	docker run -v ${DB_VOLUME}:/var/lib/mysql -p ${DB_PORT}:3306 -e MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} --privileged=true --restart unless-stopped --name mariadb -d mariadb
}

#  安装 dokcer 版本 gogs
function docker_gogs(){
	#  拉取 gogs
	docker pull gogs/gogs
	#  创建 gogs 数据卷
	if [ ! -d ${APP_VOLUME}/gogs ];then
		mkdir -p ${APP_VOLUME}/gogs
	fi
	#  启动 gogs
	docker run -v /etc/localtime:/etc/localtime  -v ${APP_VOLUME}/gogs/:/data -p ${GOGS_SSH}:22 -p ${GOGS_PORT}:3000 --name gogs -d  gogs/gogs
}

version: "3"
services:
  gogs:
    image: gogs/gogs
    container_name: gogs
    ports:
      - "8022:22"
      - "3000:3000"
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - /app/gogs/data:/data
      - /app/gogs/app:/app/gogs
    restart: always
    external_links:
      - mysql
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
    networks:
     - mynet
networks:
  mynet:
    external: true













gogs:
  image: docker.io/gogs/gogs:latest
  links:
    - mysql-gogs:mysql
  ports:
    - "10022:22"
    - "10080:3000"
  volumes:
    - /opt/docker/gogs/:/data/docker/gogs
  restart: always
  depends_on:
    - mysql

mysql-gogs:
  image: docker.io/mysql:5.7.7
  ports:
    - "3306:3306"
  volumes:
    - ./mysql-gogs/mysql:/var/lib/mysql
    - ./mysql-gogs/conf.d:/etc/mysql/conf.d:rw
  environment:
    - MYSQL_DATABASE=gogs
    - MYSQL_USER=gogs
    - MYSQL_PASSWORD=gogs
    - MYSQL_ROOT_PASSWORD=*****
  command: mysqld --lower_case_table_names=1 --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
  restart: always



version: '2.3'
services:
    mysql:
      image: mysql:5.7
      restart: always
      environment:
        - MYSQL_ROOT_PASSWORD=root
        - MYSQL_DATABASE=gogs
      volumes:
        - ./data/mysql:/var/lib/mysql
        - ./data/conf:/etc/mysql/conf.d
    gogs:
      image: gogs/gogs:latest
      restart: always
      ports:
        - "11022:22"
        - "11080:3000"
      volumes:
        - ./data/gogs:/data
      links:
        - mysql
      depends_on:
        - mysql


docker run -v /app/db:/var/lib/mysql -p 8001:3306 -e MYSQL_ROOT_PASSWORD=594hxs  --privileged=true --restart unless-stopped --name mariadb -d mariadb
docker run -v /etc/localtime:/etc/localtime  -v /app/gogs/:/data -p 8003:22 -p 8002:3000 --privileged=true --restart unless-stopped --name gogs -d gogs/gogs











